import Taro from '@tarojs/taro'
import { host } from '../utils/http'

// 用户登录
export function wxLogin(params) {
    return Taro.request({
        url: host + '/login/wx/mini',
        method: "POST",
        data: params,
        header: {
            'content-type': 'application/json' // 默认值
        },
        success: (res) => { console.log('消息请求成功', res, '参数:', params) },
        // fail: (e) => {
        //     console.log('http://localhost:80/ai/getConfig' + ', sendGet消息请求失败:', e)
        // }
    })
}

// 用户信息
export async function getUserInfo(params) {
    return Taro.request({
        url: host + '/user/info',
        method: "GET",
        data: params,
        header: {
            'content-type': 'application/json',
            'token': Taro.getStorageSync('userToken'),
        },
        success: (res) => {
            console.log('sendGet消息请求成功', res, '参数:', params)
            // callback.success(res)
        },
        fail: (e) => {
            console.log('http://localhost:80/ai/getConfig' + ', sendGet消息请求失败:', e)
            // callback.error && callback.error(new Error(e.errMsg))
        }
    })
}

// 积分信息
export async function getScoreInfo(params) {
    return Taro.request({
        url: host + '/ai/getConfig',
        method: "GET",
        data: params,
        header: {
            'content-type': 'application/json',
            'token': Taro.getStorageSync('userToken'),
        },
        success: (res) => {
            console.log('sendGet消息请求成功', res, '参数:', params)
            // callback.success(res)
        },
        fail: (e) => {
            console.log('http://localhost:80/ai/getConfig' + ', sendGet消息请求失败:', e)
            // callback.error && callback.error(new Error(e.errMsg))
        }
    })
}

// 增加积分
export async function addScore(params) {
    return Taro.request({
        url: host + '/point/increment',
        method: "POST",
        data: params,
        header: {
            'content-type': 'application/json',
            'token': Taro.getStorageSync('userToken'),
        },
        success: (res) => {
            console.log('sendGet消息请求成功', res, '参数:', params)
            // callback.success(res)
        },
        fail: (e) => {
            console.log('http://localhost:80/ai/getConfig' + ', sendGet消息请求失败:', e)
            // callback.error && callback.error(new Error(e.errMsg))
        }
    })
}

// 消耗积分
export async function costScore(params) {
    return Taro.request({
        url: host + '/point/decrement',
        method: "POST",
        data: params,
        header: {
            'content-type': 'application/json',
            'token': Taro.getStorageSync('userToken'),
        },
        success: (res) => {
            console.log('sendGet消息请求成功', res, '参数:', params)
            // callback.success(res)
        },
        fail: (e) => {
            console.log('http://localhost:80/ai/getConfig' + ', sendGet消息请求失败:', e)
            // callback.error && callback.error(new Error(e.errMsg))
        }
    })
}


